package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import utils.YUtils;

import java.util.*;
import models.*;

/**
 * Manage Roles related operations.
 */

public class Roles extends Controller {
  
    public static void index() {
    	List<Role> roles = Role.findAll();
    	String rj = Role.toJson(roles);
    	String roleJson = YUtils.ligerGridData(rj, roles.size());
        render(roleJson);
    }

    /**
     * Get Roles json.
     */
    public static void json(int page, int pagesize) {
    	List<Role> roles = Role.findAll();
    	String json = YUtils.ligerGridData(Role.toJson(roles),roles.size());
    	
    	renderJSON(json);
    }

    /**
     * Update a Role.
     */
    public static void save(Role role) {
        role.save();
        ok();
    }
    
    /**
     * Delete a Role.
     */
    public static void delete(long id) {
        Role r = Role.findById(id);
        RoleMenu.delete("role=?", r);
        r.delete();
        ok();
    }
}
